package com.example.demo;

import jakarta.servlet.http.HttpServletResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/resp")
@Controller
public class RespController {
    //返回页面
    @RequestMapping("/r1")
    public String returnPage(){
        return "index.html";
    }
    //返回数据,则Controller+ResponseBody=RestController
    @ResponseBody
    @RequestMapping("/r2")
    public String returnData(){
        return "我是前端需要的数据";
    }
    @ResponseBody
    @RequestMapping("/r3")
    public String returnHTML(){
        return "<h5>我是一级标题</h5>";
    }
    @ResponseBody
    @RequestMapping(value = "/r4",produces = "text/plain")
    public String returnText(){
        return "<h1>我是一级标题</h1>";
    }
    @ResponseBody
    @RequestMapping("/r5")
    public UserInfo returnJson(){
        UserInfo userInfo=new UserInfo("Maybe",15);
        return userInfo;
    }
    @ResponseBody
    @RequestMapping("/r6")
    public UserInfo setStatus(HttpServletResponse response){
        response.setStatus(404);
        UserInfo userInfo=new UserInfo("Maybe",10);
        return userInfo;
    }
    @ResponseBody
    @RequestMapping("/r7")
    public String setHeader(HttpServletResponse response){
        response.setHeader("Maybe","maybe");
        return "设置Header成功";
    }









}
